package com.zhiyiang.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhiyiang.pojo.Hotel;
import com.zhiyiang.service.hotel.HotelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/hotel")
public class HotelController {
    @Autowired
    private HotelService hotelService;
    @GetMapping("getHotels")
    public List<Hotel> getHotels(){
        return hotelService.getHotels();
    }
    //获取酒店列表
    @GetMapping(value = "/findAll/{current}/{size}")
    @ResponseBody
    public Page<Hotel> doHotel(@PathVariable("current") Integer current, @PathVariable("size") Integer size){
        Page<Hotel> allHotel = hotelService.getAllHotel(current, size);
        return allHotel;
    }
    //根据酒店名查询酒店
    @GetMapping (value = "/findHotel/{query}/{current}/{size}")
    @ResponseBody
    public Page<Hotel> doHotel(@PathVariable("query") String query,@PathVariable("current") Integer current,@PathVariable("size") Integer size){
        Page<Hotel> allUser = hotelService.getHotel(query,current,size);
        return allUser;
    }

    //添加用户
    @PostMapping (value = "/addHotel")
    @ResponseBody
    public Boolean addHotel(@RequestBody Hotel hotel){
        Boolean flag = hotelService.addHotel(hotel);
        System.out.println(flag);
        return flag;
    }
    //获取当前行酒店
    @GetMapping(value = "/getHotel/{hotelcode}")
    @ResponseBody
    public Hotel getHotel(@PathVariable("hotelcode") String hotelcode){
        Hotel hotel = hotelService.getHotel(hotelcode);
        return hotel;
    }
    //更新酒店
    @PutMapping(value = "updateHotel/{hotelcode}")
    @ResponseBody
    public Boolean updateHotel(@PathVariable("hotelcode") String hotelcode,
                              @RequestBody Hotel hotel){
        Boolean flag = hotelService.updateHotel(hotelcode, hotel);
        return flag;
    }
    //删除当前行酒店
    @GetMapping(value = "/deleteHotel/{hotelcode}")
    @ResponseBody
    public Boolean deleteHotel(@PathVariable("hotelcode") String hotelcode){
        Boolean flag = hotelService.deleteHotel(hotelcode);
        return flag;
    }
}
